package com.jiawa.train.business.controller.admin;

import com.jiawa.train.business.domain.Req.StationQueryReq;
import com.jiawa.train.business.domain.Req.StationSaveReq;
import com.jiawa.train.business.domain.resp.StationQueryResp;
import com.jiawa.train.business.service.StationService;
import com.jiawa.train.common.resp.CommonResp;
import com.jiawa.train.common.resp.PageResp;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("admin/station")
public class AdminStationController {

    @Autowired
    private StationService stationService;

    @GetMapping("/query-all")
    public CommonResp<List<StationQueryResp>> queryList() {
        List<StationQueryResp> list = stationService.queryAll();
        return new CommonResp<>(list);
    }

    @PostMapping("/save")
    public CommonResp<Object> save(@RequestBody StationSaveReq station) {
        stationService.save(station);
        return new CommonResp<>();
    }

    @GetMapping("/query-list")
    public CommonResp<PageResp<StationQueryResp>> queryList(@Valid StationQueryReq stationQueryReq) {
        PageResp<StationQueryResp> queryList = stationService.queryList(stationQueryReq);
        return new CommonResp<>(queryList);
    }

    @DeleteMapping("/delete/{id}")
    public CommonResp<Object> delete(@PathVariable Long id) {
        stationService.delete(id);
        return new CommonResp<>();
    }

}
